package com.example.springboot2023nocv.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot2023nocv.entity.NocvNews;
import com.example.springboot2023nocv.entity.RiskZone;
import com.example.springboot2023nocv.entity.User;
import com.example.springboot2023nocv.service.RiskZoneService;
import com.example.springboot2023nocv.vo.DataView;
import com.example.springboot2023nocv.vo.RiskZoneVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/zone")
public class RiskZoneController {

    @Autowired
    private RiskZoneService riskZoneService;

    @RequestMapping("/toZone")
    public String toZone(){
        return "zone/zone";
    }

    @RequestMapping("/listRiskZone")
    @ResponseBody
    public DataView listZone(RiskZoneVo riskZoneVo){
        QueryWrapper<RiskZone> queryWrapper = new QueryWrapper<>();
//        IPage<RiskZone> page = new Page<>(riskZoneVo.getPage(),riskZoneVo.getLimit());
        queryWrapper.like(StringUtils.isNotBlank(riskZoneVo.getProvince()),
                "province",riskZoneVo.getProvince());
        queryWrapper.eq(StringUtils.isNotBlank(riskZoneVo.getCity()),
                "city",riskZoneVo.getCity());
        queryWrapper.eq(StringUtils.isNotBlank(riskZoneVo.getCounty()),
                "county",riskZoneVo.getCounty());
        IPage<RiskZone> iPage = new Page<>(riskZoneVo.getPage(),riskZoneVo.getLimit());
        riskZoneService.page(iPage, queryWrapper);
        return new DataView(iPage.getTotal(),iPage.getRecords());
    }
}
